#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums)
    {
        vector<vector<int>> res;
        sort(nums.begin(), nums.end());
        int n = nums.size();
        for (int fir = 0; fir < n; fir++)
        {
            if (fir > 0 && nums[fir] == nums[fir - 1]&& fir < n) fir++;
            int target = -nums[fir];
            int thir = n - 1;
            for (int sec = fir + 1; sec < n; sec++)
            {
                if (sec > fir + 1 && nums[sec] == nums[sec - 1]&& sec < n) sec++;
                if (sec<thir && nums[sec] + nums[thir]>target) thir--;
                if (sec == thir) break;
                if (nums[sec] + nums[thir] == target)
                    res.push_back({ -target,nums[sec],nums[thir] });
            }
        }
        return res;

    }
};

void main()
{
    Solution s01;
    vector<int> v1 = { 3, 0, -2, -1, 1, 2 };
    s01.threeSum(v1);
}